﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BISPOS.Repository;
using DevExpress.XtraEditors.Controls;
namespace BISPOS
{
    public partial class AddCustomerUserControl : DevExpress.XtraEditors.XtraUserControl
    {
        CustomerRepository customerRepository = new CustomerRepository();
        MainForm mainForm;
        public AddCustomerUserControl(MainForm mainForm)
        {
            InitializeComponent();
            this.mainForm = mainForm;
            // initialize
            // end
        }



        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                customerRepository.AddCustomer(codeTextEdit.Text, nameTextEdit.Text,
                    sexTextEdit.Text, addressMemoEdit.Text, Convert.ToDecimal(loanLimit.Text));
                MessageBox.Show("บันทึกแล้ว");

                mainForm.mainGroupControl.Controls.Clear();
                EditCustomerUserControl control = new EditCustomerUserControl();
                mainForm.mainGroupControl.Controls.Add(control);
                control.searchTextEdit.Text = codeTextEdit.Text;
                control.searchTextEdit.Focus();

            }
            catch { MessageBox.Show("เกิดข้อผิดพลาด"); }
        }
    }
}
